package reflect;

import java.lang.reflect.Method;

/**
 * 调用有参方法
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();

        //say(String info)
        Method method = cls.getMethod("say",String.class);//第二个参数开始为方法的参数列表
        //obj.say("你好");
        method.invoke(obj,"你好");//第二个参数开始为实参


        //say(String info,int count)
        Method method2 = cls.getMethod("say",String.class,int.class);
        //obj.say("你好");
        method2.invoke(obj,"嘿嘿",5);
    }
}






